package sk.uniza.fri.cerviix.server;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.logging.StreamHandler;

import sk.uniza.fri.cerviix.server.network.NetworkManager;

public class Server
{
	public static final String NAME = "CerviiX";
	public static final Logger log = Logger.getLogger(NAME);
	
	static
	{
		StreamHandler consoleHandler = new StreamHandler(System.out, new SimpleFormatter());
		
		log.addHandler(consoleHandler);
		
		try
		{	
			FileHandler fileHandler = new FileHandler("./log.txt", true);
			fileHandler.setFormatter(new SimpleFormatter());
			
			log.addHandler(fileHandler);
			log.setLevel(Level.ALL);
			
			log.info("Logger connected.");
		}
		catch (IOException e)
		{
			System.out.println("Can't initialize server log.");
		}
	}
	
	public static void main(String arguments[])
	{
		Server server = new Server();
		server.run();
	}
	
	private NetworkManager networkManager;
	private Game game;
	
	public void run()
	{
		Server.log.info("CerviiX Server started.");
		
		networkManager = new NetworkManager();
		
		game = new Game(networkManager);
		game.run();
		
		Server.log.info("Server stopped.");
	}
}
